package com.ilancuo.thinkinjava.chapter_07;

class Insect {
    private int i = 9;
    protected int j;

    Insect() {
        System.out.println("i = " + i + ", j = " + j);
        j = 39;
    }

    private static int x1 = printInit("static Insect.x1 initialized");

    static int printInit(String s) {
        System.out.println(s);
        return 47;
    }
}

public class Beetle extends Insect {
    private int k = printInit("Beetle.k initialized");

    public Beetle() {
        System.out.println("k = " + k);
        System.out.println("j = " + j);
    }

    private static int x2 = printInit("static Beetle.x2 initialized");

    public static void main(String[] args) {
        System.out.println("Beetle constructor");
        Beetle b = new Beetle();
    }
}

/**
 * out
 * ----------------------------
 * static Insect.x1 initialized.        1. 初始化父类的静态成员变量
 * static Beetle.x2 initialized.        2. 初始化子类的静态成员变量
 * Beetle constructor.                  3. main()方法中的语句
 * i = 9, j = 0;                        4. 父类的构造方法
 *                                      5. 父类的非静态成员变量
 * Beetle.k initialized.                6. 子类的非静态成员变量
 * k = 47
 * j = 39
 */